﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title></title>
	<style type="text/css">
		@import url('global.css');
	</style>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
	<script type="text/javascript" src="http://ajax.cdnjs.com/ajax/libs/json2/20110223/json2.js"></script>
	<script type="text/javascript" src="voting-sites.js"></script>
	<script type="text/javascript" src="votes-downloader.js"></script>
	<script type="text/javascript">

		function buildNodes($listNodes) {
			var nodes = [];

			$listNodes.each(function (index, item) {
				var node = {};
				var $a = $("> a", item);
				var $children = $("> ul > li", item);

				node.name = $a.text();
				node.href = $a.attr('href');
				if ($children.length > 0)
					node.subordinates = buildNodes($children);
				else {
					node.href = node.href.replace('type=0', 'type=226');
					node.final = true;
				}
				nodes.push(node);
			});
			return nodes;
		}


		function makePlainSites(nodesTree, nodesPlain) {
			$.each(nodesTree, function (i, n) {
				if (n.final)
					nodesPlain.push(n);
				else
					makePlainSites(n.subordinates, nodesPlain);
			});
		}


		$(document).ready(function () {
//			if (netscape != null && netscape != undefined)
//				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		
			var votingSitesPlain = [];
			var $progress = $("span.progress");

			makePlainSites(votingSites, votingSitesPlain);

			var downloader = new VotesDownloader(votingSitesPlain, function (amountDone, finished) {
				$('span', $progress).css('width', (100.0 * amountDone / votingSitesPlain.length) + '%');
				if (finished)
					$(document.body).text(JSON.stringify(votingSites));
			});

			downloader.run();
		});
	</script>
</head>
<body>
	<p>Results downloaded:<span class="progress"><span></span></span></p>
</body>
</html>
